package cn.sciento.farm.devicemanager.service.impl;

import cn.sciento.farm.devicemanager.dao.entity.DevInverter;
import cn.sciento.farm.devicemanager.dao.mapper.InverterMapper;
import cn.sciento.farm.devicemanager.service.InverterService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InverterServiceImpl implements InverterService {

    @Autowired
    InverterMapper inverterMapper;

    @Override
    public int updateOnline(String eui, int online) {
        QueryWrapper queryWrapper = new QueryWrapper<DevInverter>();
        queryWrapper.eq("eui",eui);
        DevInverter devInverter = new DevInverter();
        devInverter.setOnline(online);
        int count = inverterMapper.update(devInverter,queryWrapper);
        return count;
    }

    @Override
    public DevInverter getByEui(String eui) {
        QueryWrapper queryWrapper = new QueryWrapper<DevInverter>();
        queryWrapper.eq("eui",eui);
        return inverterMapper.selectOne(queryWrapper);
    }

    @Override
    public int updateById(DevInverter deviceInverter) {
        return inverterMapper.updateById(deviceInverter);
    }

    @Override
    public int insert(DevInverter devInverter) {
        return inverterMapper.insert(devInverter);
    }

    @Override
    public DevInverter getById(long id) {
        return inverterMapper.selectById(id);
    }

    @Override
    public List<DevInverter> getByAreaId(int areaId) {
        QueryWrapper queryWrapper = new QueryWrapper<DevInverter>();
        queryWrapper.eq("area_id",areaId);
        List<DevInverter> devInverters = inverterMapper.selectList(queryWrapper);
        return devInverters;
    }

    @Override
    public int deleteById(Long id) {
        return inverterMapper.deleteById(id);
    }

    @Override
    public int deleteByAreaId(Integer areaId) {
        QueryWrapper queryWrapper = new QueryWrapper<DevInverter>();
        queryWrapper.eq("area_id",areaId);
        return inverterMapper.delete(queryWrapper);
    }
}
